package com.ysj.demo.accompanynetwork.fragment;

import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.support.annotation.Nullable;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.google.gson.Gson;
import com.ysj.demo.accompanynetwork.ApiServiceUntil;
import com.ysj.demo.accompanynetwork.R;
import com.ysj.demo.accompanynetwork.util.SpUtil;
import com.ysj.demo.accompanynetwork.util.StatusBarUtil;
import com.ysj.demo.accompanynetwork.bean.AreaBean;
import com.ysj.demo.accompanynetwork.bean.AreaRequest;
import com.ysj.demo.accompanynetwork.bean.AreaResult;
import com.ysj.demo.accompanynetwork.bean.BaseBean;
import com.ysj.demo.accompanynetwork.bean.ImageResult;
import com.ysj.demo.accompanynetwork.bean.PlayerTypeBean;
import com.ysj.demo.accompanynetwork.bean.PlayerTypeResult;
import com.ysj.demo.accompanynetwork.bean.PublishBean;
import com.ysj.demo.accompanynetwork.bean.UserBean;
import com.ysj.demo.accompanynetwork.util.ToolUtil;
import com.ysj.demo.accompanynetwork.weight.CityPopupWindow;
import com.ysj.demo.accompanynetwork.weight.PlayerTypePopWindow;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by 80530 on 2018/8/6.
 */

public class PublishRentYourselfFragment extends Fragment implements View.OnClickListener {
    private LinearLayout playTypeLl, firstCityLl, secondCityLl, threeCityLl;
    private TextView playTypeTv, firstCityTv, secondCityTv, threeCityTv;
    private List firstList, secondList, threeList, playerList;
    private AreaBean firstCity, secondCity, threeCity;
    private PlayerTypeBean playerType;
    private CityPopupWindow menuWindow;
    private PlayerTypePopWindow playerWindow;

    private EditText titleEt, playerMateEt, oneOtherEt, languageEt, jobEt, educationEt, nativePlaceEt, twoOtherEt, qqEt, phoneEt, weixinEt;

    private RadioGroup sexRg, remunerationRg, managerRg, ageRg, heightRg, weightRg;
    private String playerTypeStr, sexStr, managerStr, ageStr, heightStr, weightStr;
    private String url;
    private int remunerationStr;
    private TextView publishTv;

    private final int PERMISSION_REQUEST_CODE = 1;//申请权限的请求码
    private static final int PHOTO_REQUEST_GALLERY = 2;// 从相册中选择
    private static final int PHOTO_REQUEST_CUT = 3;// 裁剪之后
    private ImageView uploadIv;
    private File tempFile;
    private String userId;

    public PublishRentYourselfFragment() {
        // Required empty public constructor
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        userId = (String) SpUtil.getParam(getActivity(), SpUtil.USER_ID, "");
        firstList = new ArrayList();
        secondList = new ArrayList();
        threeList = new ArrayList();
        playerList = new ArrayList();
        firstCity = new AreaBean();
        firstCity.setName("不限");
        firstCity.setId(-1);
        firstCity.setParentid(-1);

        secondCity = new AreaBean();
        secondCity.setName("不限");
        secondCity.setId(-1);
        secondCity.setParentid(-1);

        threeCity = new AreaBean();
        threeCity.setName("不限");
        threeCity.setId(-1);
        threeCity.setParentid(-1);

        playerType = new PlayerTypeBean();

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_publish_rent_yourself_layout, container, false);
        uploadIv = view.findViewById(R.id.upload_iv);
        firstCityLl = view.findViewById(R.id.first_city_ll);
        firstCityTv = view.findViewById(R.id.first_level_tv);
        secondCityLl = view.findViewById(R.id.second_city_ll);
        secondCityTv = view.findViewById(R.id.second_level_tv);
        threeCityLl = view.findViewById(R.id.three_city_ll);
        threeCityTv = view.findViewById(R.id.three_level_tv);
        playTypeLl = view.findViewById(R.id.player_mate_type_ll);
        playTypeTv = view.findViewById(R.id.player_mate_type_tv);
        titleEt = view.findViewById(R.id.title_et);
        playerMateEt = view.findViewById(R.id.player_mate_name_et);
        oneOtherEt = view.findViewById(R.id.other_et);
        languageEt = view.findViewById(R.id.language_et);
        jobEt = view.findViewById(R.id.job_et);
        educationEt = view.findViewById(R.id.education_et);
        nativePlaceEt = view.findViewById(R.id.native_place_et);
        twoOtherEt = view.findViewById(R.id.two_other_et);
        qqEt = view.findViewById(R.id.qq_et);
        phoneEt = view.findViewById(R.id.phone_et);
        weixinEt = view.findViewById(R.id.weixin_et);

        remunerationRg = view.findViewById(R.id.remuneration_rg);
        sexRg = view.findViewById(R.id.sex_rg);
        managerRg = view.findViewById(R.id.marriage_rg);
        ageRg = view.findViewById(R.id.age_rg);
        heightRg = view.findViewById(R.id.height_rg);
        weightRg = view.findViewById(R.id.weight_rg);

        publishTv = view.findViewById(R.id.publish_tv);
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        firstCityTv.setText(firstCity.getName());
        secondCityTv.setText(secondCity.getName());
        threeCityTv.setText(threeCity.getName());
        initListener();
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);

    }

    @Override
    public void onDetach() {
        super.onDetach();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            //上传图片
            case R.id.upload_iv:
                checkPermissionAndLoadImages();
                break;
            case R.id.first_city_ll:
                getPlayCity(1, null);
                break;
            case R.id.second_city_ll:
                if (firstCity != null) {
                    if (firstCity.getParentid() > -1) {
                        getPlayCity(2, firstCity.getId() + "");
                    } else {
                        ToolUtil.ToastShow(getActivity().getApplication(), "请选择省份");
                    }
                } else {
                    ToolUtil.ToastShow(getActivity().getApplication(), "请选择省份");
                }
                break;
            case R.id.three_city_ll:
                if (secondCity != null) {
                    if (secondCity.getParentid() > -1) {
                        getPlayCity(3, secondCity.getId() + "");
                    } else {
                        ToolUtil.ToastShow(getActivity(), "请选择直辖市");
                    }
                } else {
                    ToolUtil.ToastShow(getActivity(), "请选择直辖市");
                }
                break;
            case R.id.player_mate_type_ll:
                getPlaymateType();
                break;
            case R.id.publish_tv:
                checkPostLendSelfTask(new UserBean(userId));
                break;
        }
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == PHOTO_REQUEST_GALLERY) {
            // 从相册返回的数据
            if (data != null) {// 得到图片的全路径
                Uri uri = data.getData();
                upLoad2Server(uri);
                //  crop(uri);
            } else if (requestCode == PHOTO_REQUEST_CUT) {//从剪切图片返回的数据
                if (data != null) {
                    Bitmap bitmap = data.getParcelableExtra("data");
                    //将bitmap转换为Uri
                    Uri uri = Uri.parse(MediaStore.Images.Media.insertImage(getActivity().getContentResolver(), bitmap, null, null));
                    //对非正确的Uri处理，这类Uri存在手机的external.db中，可以查询_data字段查出对应文件的uri
                    if (uri.getPath().contains("external")) {
                        uri = external(uri.getPath());
                    }
                    //在这可以拿到裁剪后的图片Uri,然后进行你想要的操作
                    upLoad2Server(uri);
                }
                try {
                    tempFile.delete();//将临时文件删除
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
        super.onActivityResult(requestCode, resultCode, data);
    }

    private void initListener() {
        uploadIv.setOnClickListener(this);
        firstCityLl.setOnClickListener(this);
        secondCityLl.setOnClickListener(this);
        threeCityLl.setOnClickListener(this);
        playTypeLl.setOnClickListener(this);
        publishTv.setOnClickListener(this);
        sexRg.check(R.id.no_limit_rb);
        sexRg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId) {
                    case R.id.no_limit_rb:
                        sexStr = "";
                        break;
                    case R.id.girl_rb:
                        sexStr = "0";
                        break;
                    case R.id.boy_rb:
                        sexStr = "1";
                        break;
                }
            }
        });
        remunerationRg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId) {
                    case R.id.one_remuneration_rb:
                        remunerationStr = 0;
                        break;
                    case R.id.two_remuneration_rb:
                        remunerationStr = 1;
                        break;
                    case R.id.three_remuneration_rb:
                        remunerationStr = 2;
                        break;
                    case R.id.four_remuneration_rb:
                        remunerationStr = 3;
                        break;
                }
            }
        });
        managerRg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId) {
                    case R.id.no_limit_marriage_rb:
                        managerStr = "0";
                        break;
                    case R.id.no_marriage_rb:
                        managerStr = "1";
                        break;
                    case R.id.have_marriage_rb:
                        managerStr = "2";
                        break;
                    case R.id.divorce_rb:
                        managerStr = "3";
                        break;
                }
            }
        });
        ageRg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId) {
                    case R.id.no_limit_age_rb:
                        ageStr = "0";
                        break;
                    case R.id.one_age_rb:
                        ageStr = "1";
                        break;
                    case R.id.two_age_rb:
                        ageStr = "2";
                        break;
                    case R.id.three_age_rb:
                        ageStr = "3";
                        break;
                }
            }
        });
        heightRg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId) {
                    case R.id.one_height_rb:
                        heightStr = "0";
                        break;
                    case R.id.two_height_rb:
                        heightStr = "1";
                        break;
                    case R.id.three_height_rb:
                        heightStr = "2";
                        break;
                    case R.id.four_height_rb:
                        heightStr = "3";
                        break;
                }
            }
        });
        weightRg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId) {
                    case R.id.no_limit_weight_rb:
                        weightStr = "0";
                        break;
                    case R.id.one_weight_rb:
                        weightStr = "1";
                        break;
                    case R.id.two_weight_rb:
                        weightStr = "2";
                        break;
                    case R.id.three_weight_rb:
                        weightStr = "3";
                        break;
                }
            }
        });
    }

    public void gallery() {
        Intent intent = new Intent(Intent.ACTION_PICK);
        intent.setType("image/*");
        startActivityForResult(intent, PHOTO_REQUEST_GALLERY);//携带请求码
    }

    private void crop(Uri uri) {
        Intent intent = new Intent("com.android.camera.action.CROP");
        intent.setDataAndType(uri, "image/*");
        intent.putExtra("crop", "true");
        // 裁剪框的比例，1：1
        intent.putExtra("aspectX", 1);
        intent.putExtra("aspectY", 1);
        // 裁剪后输出图片的尺寸大小
        intent.putExtra("outputX", 250);
        intent.putExtra("outputY", 250);
        intent.putExtra("outputFormat", "JPEG");// 图片格式
        intent.putExtra("noFaceDetection", true);// 取消人脸识别
        intent.putExtra("return-data", true);
        startActivityForResult(intent, PHOTO_REQUEST_CUT); // 开启一个带有返回值的Activity，请求码为PHOTO_REQUEST_CUT
    }

    private Uri external(String external) {
        String myImageUrl = "content://media" + external;
        Uri uri = Uri.parse(myImageUrl);
        String[] proj = {MediaStore.Images.Media.DATA};
        Cursor actualimagecursor = getActivity().managedQuery(uri, proj, null, null, null);
        int actual_image_column_index = actualimagecursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        actualimagecursor.moveToFirst();
        String img_path = actualimagecursor.getString(actual_image_column_index);
        File file = new File(img_path);
        Uri fileUri = Uri.fromFile(file);
        return fileUri;
    }

    /**
     * 检查权限并加载SD卡里的图片。
     */
    private void checkPermissionAndLoadImages() {
        int hasWriteContactsPermission = ContextCompat.checkSelfPermission(getActivity().getApplicationContext(),
                Manifest.permission.WRITE_EXTERNAL_STORAGE);
        if (hasWriteContactsPermission == PackageManager.PERMISSION_GRANTED) {
            //有权限，加载图片。
            gallery();
        } else {
            //没有权限，申请权限。
            ActivityCompat.requestPermissions(getActivity(),
                    new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, PERMISSION_REQUEST_CODE);
        }
    }

    /**
     * 处理权限申请的回调。
     */
    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
        if (requestCode == PERMISSION_REQUEST_CODE) {
            if (grantResults.length > 0
                    && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                //允许权限，加载图片。
                gallery();
            } else {
                //拒绝权限，弹出提示框。
                ToolUtil.ToastShow(getActivity(), "没有权限");
            }
        }
    }

    //上传图片
    private void upLoad2Server(Uri uri) {
        String[] proj = {MediaStore.Images.Media.DATA};

        Cursor actualimagecursor = getActivity().managedQuery(uri, proj, null, null, null);

        int actual_image_column_index = actualimagecursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);

        actualimagecursor.moveToFirst();

        String img_path = actualimagecursor.getString(actual_image_column_index);

        File file = null;
        try {
            file = new File(img_path);
        } catch (Exception e) {
            e.printStackTrace();
        }

        RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"), file);
        MultipartBody.Part body = MultipartBody.Part.createFormData("file", file.getName(), requestBody);

        Call<ImageResult> call = ApiServiceUntil.getInstance().getmApi().postImageTask(body);
        call.enqueue(new Callback<ImageResult>() {
            @Override
            public void onResponse(Call<ImageResult> call, Response<ImageResult> response) {
                ImageResult result = response.body();
                if (result.getCode() == 0) {
                    url = result.getData().getUrl();
                    Glide.with(getActivity()).load(result.getData().getUrl()).into(uploadIv);
                }
                Log.i("PublishFindPlayer_图片", new Gson().toJson(result));
            }

            @Override
            public void onFailure(Call<ImageResult> call, Throwable t) {
                Log.i("PublishFindPlayer_图片", t.toString());
            }
        });
    }

    //获取玩伴类型
    private void getPlaymateType() {
        Call<PlayerTypeResult> call =ApiServiceUntil.getInstance().getmApi().getPlaymateTypeTask();
        call.enqueue(new Callback<PlayerTypeResult>() {
            @Override
            public void onResponse(Call<PlayerTypeResult> call, Response<PlayerTypeResult> response) {
                PlayerTypeResult body = response.body();
                if (body.getCode() == 0) {
                    playerList.clear();
                    playerList = body.getData();
                    playerWindow = new PlayerTypePopWindow(getActivity(), playerList, itemsPlayerTypeClick);
                    //显示窗口
                    playerWindow.showAtLocation(getActivity().findViewById(R.id.main), Gravity.CENTER, 0, 0); //设置layout在PopupWindow中显示的位置
                } else {
                    ToolUtil.ToastShow(getActivity(), "获取失败");
                }
                Log.i("RentYourselfFragment", new Gson().toJson(body));
            }

            @Override
            public void onFailure(Call<PlayerTypeResult> call, Throwable t) {
                Log.i("RentYourselfFragment", t.toString());
            }
        });
    }

    //获取城市
    private void getPlayCity(final int type, String id) {
        AreaRequest bean = new AreaRequest();
        bean.setLevel(type);
        bean.setParentid(id);
        ToolUtil.ToastShow(getActivity(), new Gson().toJson(bean));
        Call<AreaResult> call = ApiServiceUntil.getInstance().getmApi().getAreaTask(bean);
        call.enqueue(new Callback<AreaResult>() {
            @Override
            public void onResponse(Call<AreaResult> call, Response<AreaResult> response) {
                AreaResult body = response.body();
                if (body.getCode() == 0) {
                    switch (type) {
                        case 1:
                            firstList.clear();
                            firstList = body.getData();
                            menuWindow = new CityPopupWindow(getActivity(), firstList, itemsOnClick);
                            //显示窗口
                            menuWindow.showAtLocation(getActivity().findViewById(R.id.main), Gravity.CENTER, 0, 0); //设置layout在PopupWindow中显示的位置
                            break;
                        case 2:
                            secondList.clear();
                            secondList = body.getData();
                            menuWindow = new CityPopupWindow(getActivity(), secondList, itemsSecondOnClick);
                            //显示窗口
                            menuWindow.showAtLocation(getActivity().findViewById(R.id.main), Gravity.CENTER, 0, 0); //设置layout在PopupWindow中显示的位置
                            break;
                        case 3:
                            threeList.clear();
                            threeList = body.getData();
                            menuWindow = new CityPopupWindow(getActivity(), threeList, itemsThreeOnClick);
                            //显示窗口
                            menuWindow.showAtLocation(getActivity().findViewById(R.id.main), Gravity.CENTER, 0, 0); //设置layout在PopupWindow中显示的位置

                            break;
                    }
                } else {
                    ToolUtil.ToastShow(getActivity(), "获取失败");
                }

                Log.i("RentYourselfFragment", new Gson().toJson(body));
            }

            @Override
            public void onFailure(Call<AreaResult> call, Throwable t) {
                Log.i("RentYourselfFragment", t.toString());
            }
        });
    }

    //发布前的检查
    private void checkPostLendSelfTask(UserBean bean) {
        Log.i("RentYourselfFragment检查", new Gson().toJson(bean));
        Call<BaseBean> call = ApiServiceUntil.getInstance().getmApi().checkPostlendSelfTask(bean);
        call.enqueue(new Callback<BaseBean>() {
            @Override
            public void onResponse(Call<BaseBean> call, Response<BaseBean> response) {
                BaseBean body = response.body();
                if (body.getCode() == 0) {
//                    PublishBean bean = new PublishBean();
//                    String title = titleEt.getText().toString().trim();
//                    bean.setCreateUserId(userId);
//                    bean.setTitle(title);
//                    bean.setPortrait(url);
//                    bean.setStatus("0");
//                    bean.setPostStatus("0");
//                    bean.setPartnerProvinceCode(firstCity.getId());
//                    bean.setPartnerCityCode(secondCity.getId());
//                    bean.setPartnerCountyCode(threeCity.getId());
//                    bean.setPartnerPayCode(remunerationStr);
//                    bean.setPartnerType(playerType.getPlaytype());
//                    String partnerStr = playerMateEt.getText().toString().trim();
//                    bean.setPartnerItem(partnerStr);
//                    String partnerRemarkStr = oneOtherEt.getText().toString().trim();
//                    bean.setPartnerRemark(partnerRemarkStr);
//                    bean.setSex(sexStr);
//                    bean.setMarrystatus(managerStr);
//                    bean.setAge(ageStr);
//                    bean.setHeight(heightStr);
//                    bean.setWeight(weightStr);
//                    String languageStr = languageEt.getText().toString().trim();
//                    bean.setLanguage(languageStr);
//                    String jobStr = jobEt.getText().toString().trim();
//                    bean.setVocation(jobStr);
//                    String educationStr = educationEt.getText().toString().trim();
//                    bean.setEducation(educationStr);
//                    String nativePlaceStr = nativePlaceEt.getText().toString().trim();
//                    bean.setEducation(nativePlaceStr);
//                    String remarkStr = twoOtherEt.getText().toString().trim();
//                    bean.setRemark(remarkStr);
//                    String qqStr = qqEt.getText().toString().trim();
//                    bean.setQq(qqStr);
//                    String phoneStr = phoneEt.getText().toString().trim();
//                    bean.setTel(phoneStr);
//                    String weixinStr = weixinEt.getText().toString().trim();
//                    bean.setWeixin(weixinStr);
//                    postLendSelfTask(bean);
                } else {
                    ToolUtil.ToastShow(getActivity(), "发布失败");
                }
                Log.i("RentYourselfFragment", new Gson().toJson(body));
            }

            @Override
            public void onFailure(Call<BaseBean> call, Throwable t) {
                Log.i("RentYourselfFragment", t.toString());
            }
        });
    }

    //发布
    private void postLendSelfTask(PublishBean bean) {
        Log.i("RentYourselfFragment发布", new Gson().toJson(bean));
        Call<BaseBean> call = ApiServiceUntil.getInstance().getmApi().postlendSelfTask(bean);
        call.enqueue(new Callback<BaseBean>() {
            @Override
            public void onResponse(Call<BaseBean> call, Response<BaseBean> response) {
                BaseBean body = response.body();
                if (body.getCode() == 0) {
                    ToolUtil.ToastShow(getActivity(), "发布成功");
                    getActivity().finish();
                } else {
                    ToolUtil.ToastShow(getActivity(), "发布失败");
                }
                Log.i("RentYourselfFragment", new Gson().toJson(body));
            }

            @Override
            public void onFailure(Call<BaseBean> call, Throwable t) {
                Log.i("RentYourselfFragment", t.toString());
            }
        });
    }

    //为弹出窗口实现监听类
    private AdapterView.OnItemClickListener itemsPlayerTypeClick = new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            playerWindow.dismiss();
            playerType = (PlayerTypeBean) playerList.get(position);

            ToolUtil.ToastShow(getActivity(), playerType.getPlayname());
            playTypeTv.setText(playerType.getPlayname());
        }
    };

    //为弹出窗口实现监听类
    private AdapterView.OnItemClickListener itemsOnClick = new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            menuWindow.dismiss();
            firstCity = (AreaBean) firstList.get(position);
            secondCity = null;
            threeCity = null;
            secondCityTv.setText("不限");
            threeCityTv.setText("不限");
            ToolUtil.ToastShow(getActivity(), firstCity.getName());
            firstCityTv.setText(firstCity.getName());
        }
    };

    //为弹出窗口实现监听类
    private AdapterView.OnItemClickListener itemsSecondOnClick = new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            menuWindow.dismiss();
            secondCity = (AreaBean) secondList.get(position);
            threeCity = null;
            threeCityTv.setText("不限");
            ToolUtil.ToastShow(getActivity(), secondCity.getName());
            secondCityTv.setText(secondCity.getName());
        }
    };

    //为弹出窗口实现监听类
    private AdapterView.OnItemClickListener itemsThreeOnClick = new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            menuWindow.dismiss();
            threeCity = (AreaBean) threeList.get(position);
            ToolUtil.ToastShow(getActivity(), threeCity.getName());
            threeCityTv.setText(threeCity.getName());
        }
    };

}
